package com.iot.manager.network.interceptors;

import android.util.Log;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class AuthInterceptor implements Interceptor {
    private static final String TAG = "AuthInterceptor";
    private String token;

    public void setToken(String token) {
        Log.d(TAG, "Setting token: " + (token != null ? "not null" : "null"));
        this.token = token;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        Request.Builder builder = original.newBuilder();
        
        if (token != null && !token.isEmpty()) {
            builder.header("Authorization", "Bearer " + token);
            Log.d(TAG, "Adding Authorization header with token");
        } else {
            Log.d(TAG, "No token available, skipping Authorization header");
        }
        
        Request request = builder.build();
        Log.d(TAG, "Request URL: " + request.url());
        Log.d(TAG, "Request headers: " + request.headers());
        
        return chain.proceed(request);
    }
} 